Skip to content

budget service - #118

Merged
Uyoxy merged 1 commit into
stellarspend:mainfrom
Noble-Devbase:feat/budgetservice-analytics-service
Aug 25, 2026
Merged

budget service#118
Uyoxy merged 1 commit into
stellarspend:mainfrom
Noble-Devbase:feat/budgetservice-analytics-service

Conversation

@Noble-Devbase

Copy link
Copy Markdown
Contributor

closes #111

PR Summary

Implement the budgets and analytics modules with real database-backed functionality, replacing the existing status-only scaffolds.
This PR adds full budget CRUD with ownership validation, introduces a new budgets table and entity, implements real transaction-based analytics queries, and consolidates the duplicate analytics modules into a single analytics module.

Changes

Budgets

  • Added budgets database migration.

  • Added Budget entity with:

    • id
    • userId
    • name
    • asset
    • amount
    • category
    • period
    • startDate
    • endDate
    • createdAt
    • updatedAt
  • Replaced BudgetsService.status() with full CRUD:

    • Create budget
    • List user budgets
    • Get a specific budget
    • Update budget
    • Delete budget
  • Added ownership checks to prevent users from accessing or modifying another user's budgets.

  • Protected budget routes with JwtAuthGuard.

Analytics

Replaced the analytics status scaffold with real PostgreSQL queries against the existing transactions table.

Implemented:

  • Spending Trend

    • Groups transactions by ISO week using date_trunc.
    • Supports configurable asset and week range.
    • Returns weekly spending totals.
  • Category Breakdown

    • Aggregates spending by category.
    • Calculates category percentages against the grand total directly in SQL.
    • Supports asset and start-date filtering.
  • Budget vs Actual

    • Joins budgets with transactions using category and asset.
    • Calculates budgeted amount, actual spending, and variance for each budget.

Analytics Consolidation

  • Removed the duplicate src/analytics-system/ module.
  • Moved any required unique functionality into src/analytics/.
  • Removed AnalyticsSystemModule from app.module.ts.
  • Updated the analytics module and controller to expose the implemented endpoints.
  • Protected analytics routes with JwtAuthGuard.

Testing

Added unit tests covering:

  • Budget creation and CRUD operations.
  • Budget ownership validation.
  • Budget update and deletion.
  • Spending trend aggregation.
  • Category breakdown and percentage calculations.
  • Budget-vs-actual calculations.
  • Analytics query behavior.

@Uyoxy

Uyoxy commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

great job

@Uyoxy
Uyoxy merged commit 35f5967 into stellarspend:main Aug 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement BudgetsService and AnalyticsService with real database queries

2 participants